
#ifndef __12_21_H__
#define __12_21_H__

#include "mcp2515.h"

#define BMS_TOTAL_INFO1		0x1818D0F3
#define BMS_TOTAL_INFO2		0x1819D0F3
#define BMS_TEM_INFO1		0x181AD0F3
#define BMS_TEM_INFO2		0x181BD0F3
#define BMS_VOL_INFO1		0x181CD0F3
#define BMS_VOL_INFO2		0x181DD0F3
#define BMS_VOL_INFO3		0x181ED0F3
#define BMS_CURRENT_INFO	0x181FD0F3
#define BMS_ALM_STATUS		0x1820D0F3
#define BMS_CHARGE_INFO		0x1806E5F4

typedef struct{
	rt_uint32_t	v_total	:16;
	rt_uint32_t	i_total	:16;
	rt_uint32_t	soc		:8;
	rt_uint32_t	life		:8;
	rt_uint32_t	ed_sta	:2;
	rt_uint32_t	ed_rev	:3;
	rt_uint32_t	ed_main	:2;
	rt_uint32_t	ed_mounth	:4;
	rt_uint32_t	ed_year	:5;
} _bms_info_1;

typedef struct{
	rt_uint32_t	pack_num	:8;
	rt_uint32_t	cell_tol	:16;
	rt_uint32_t	ser_num	:8;
	rt_uint32_t	par_num	:8;
	rt_uint32_t	elec_q	:16;
	rt_uint32_t			:8;
} _bms_info_2;	

typedef struct{
	rt_uint8_t	max_tem;
	rt_uint8_t	min_tem;
	rt_uint8_t	tem_g_num;
	rt_uint8_t	tem_g_c1;
	rt_uint8_t	tem_g_c2;
	rt_uint8_t	tem_g_c3;
	rt_uint8_t	tem_g_c4;
	rt_uint8_t	tem_g_c5;
} _bms_tem_1;

typedef struct{
	rt_uint8_t	highest_g;
	rt_uint8_t	highest_c;
	rt_uint8_t	highest_t;
	rt_uint8_t	lowest_g;
	rt_uint8_t	lowest_c;
	rt_uint8_t	lowest_t;
	rt_uint8_t	tem_range;
	rt_uint8_t			:8;
} _bms_tem_2;

typedef struct{
	rt_uint32_t	max_v_cg		:16;
	rt_uint32_t	min_v_discg		:16;
	rt_uint32_t	highest_v_cg	:8;
	rt_uint32_t	lowest_v_discg	:8;
	rt_uint32_t				:16;
} _bms_vol_1;

typedef struct{
	rt_uint8_t	vol_g_num;
	rt_uint8_t	vol_g_c1;
	rt_uint8_t	vol_g_c2;
	rt_uint8_t	vol_g_c3;
	rt_uint8_t	vol_g_c4;
	rt_uint8_t	vol_g_c5;
	rt_uint8_t	vol_g_c6;
	rt_uint8_t	vol_g_c7;
} _bms_vol_2;

typedef struct{
	rt_uint8_t	highest_g;
	rt_uint8_t	highest_c;
	rt_uint8_t	highest_v;
	rt_uint8_t	lowest_g;
	rt_uint8_t	lowest_c;
	rt_uint8_t	lowest_v;
	rt_uint8_t	vol_range;
	rt_uint8_t			:8;
} _bms_vol_3;

typedef struct{
	rt_uint16_t	cg_i_max;
	rt_uint16_t	discg_i_max;
	rt_uint16_t			:16;
	rt_uint16_t			:16;
} _bms_current;

typedef struct{
	rt_uint32_t	alm_type	:2;
	rt_uint32_t			:6;
	rt_uint32_t	alm_code1	:8;
	rt_uint32_t	alm_code2	:8;
	rt_uint32_t	alm_code3	:8;
	rt_uint32_t	power_sta	:1;
	rt_uint32_t	pre_cg_sta	:1;
	rt_uint32_t	c_cg_sta	:1;
	rt_uint32_t	f_charge	:1;
	rt_uint32_t	charge_en	:1;
	rt_uint32_t	balance_sta	:1;
	rt_uint32_t	balance_en	:1;
	rt_uint32_t			:1;
	rt_uint32_t	charge_sta	:2;
	rt_uint32_t	interlock1	:2;
	rt_uint32_t	interlock2	:2;
	rt_uint32_t			:2;
	rt_uint32_t	insul_res	:16;
} _bms_alm_status;

typedef struct{
	rt_uint8_t	charge_v_h;
	rt_uint8_t	charge_v_l;
	rt_uint8_t	charge_i_h;
	rt_uint8_t	charge_i_l;
	rt_uint8_t	charge_en	:1;
	rt_uint8_t			:7;
	rt_uint8_t			:8;
	rt_uint8_t			:8;
	rt_uint8_t			:8;
} _bms_charge;

typedef struct{
	_bms_info_1		bms_info1;
	_bms_info_2		bms_info2;
	_bms_tem_1		bms_tem1;
	_bms_tem_2		bms_tem2;
	_bms_vol_1		bms_vol1;
	_bms_vol_2		bms_vol2;
	_bms_vol_3		bms_vol3;
	_bms_current 	bms_current;
	_bms_alm_status 	bms_alm_sta;
	_bms_charge 	bms_cg;
} _bms_total_info;


rt_uint16_t can_1221_config (_bms_total_info* bms_total_info,rt_uint8_t life);

#endif